//////////////////////////////////////////////////////////////////////
////                                                              ////
////  TupleDecoder.v                                              ////
////                                                              ////
////                                                              ////
////  This file is part of the "Pico E12" project                 ////
////  http://www.picocomputing.com                                ////
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
////                                                              ////
//// Copyright (C) 2005, Pico ComputIng, Inc.                     ////
//// http://www.picocomputing.com/                                ////
////                                                              ////
//// This source file may be used and distributed withOut         ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contaIns  ////
//// the origInal copyright notice and the associated disclaimer. ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOut ANY WARRANTY; withOut even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
////////////////////////////////////////////////////////////////////JF

//This module decodes tuple read requests and reformats the data for the 16 bit PCMCIA databus
`include "PicoDefines.v"

module TupleDecoder(AttribRead, MemAddress, DataOut);

input AttribRead;
input [10:1]MemAddress;
output [15:0]DataOut;

wire AttribReadBUF;
wire [7:0]TupleAddress;
wire [7:0]TupleData;
wire MasterRead;

//AttribRead is a clock signal so it needs to go through a BUF before connecting to asynchronous logic

BUF AttribReadBuffer(.I(AttribRead), .O(AttribReadBUF));
						  
assign MasterRead = ((AttribReadBUF) && (MemAddress[10:1] <= 9'hFF));                   //When master read goes high the tuple is being read
assign TupleAddress[7:0] = (MasterRead)?MemAddress[8:1] : 8'b0;                         //Clearing the address lines while not in use saves power
assign DataOut[7:0] = (MasterRead)?(TupleData[7:0]) : 8'b0;                             //Actual tuple data output
assign DataOut[15:8] = DataOut[7:0];

E12Tuple E12Tuple(.addr(TupleAddress[7:0]), .data(TupleData[7:0]));

endmodule